package com.grocery.controller;

import com.grocery.bean.User;
import com.grocery.dao.PasswordDao;
import com.grocery.service.impl.PasswordService;
import com.grocery.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("password")
public class PasswordController {
    @Autowired
    PasswordService passwordService;

    @RequestMapping("changepassword")
    @ResponseBody
    public int changepassword(String oldpassword, String newpassword,String newpasswordagain,HttpServletRequest request) {
        HttpSession session = request.getSession();
        User u = (User) session.getAttribute(SYS.USER_LOGIN);
        int userid = u.getId();
        return passwordService.changepassword(oldpassword, newpassword,newpasswordagain,userid);
    }
}
